﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Wamm.AbstractDataAccess;
using WAMM.Domain.Services.Person;
using WAMM.Domain.Services.Photo;
using Wamm.EntityFrameworkImplementation;
using WAMM.WebUI.Infrastructure;

namespace WAMM.WebUI {
    public class RequestBootstrapper {
        public static void ConfigureUnity() {
            MvcUnity.Container
                .RegisterType<IRepositoryFactory, RepositoryFactory>(new ContainerControlledLifetimeManager())
                .RegisterType<IPrincipalProvider, WAMM.WebUI.Infrastructure.PrincipalProvider>(new ContainerControlledLifetimeManager())
                .RegisterType<ISession, Session>(new ContainerControlledLifetimeManager(),
                    new InjectionConstructor(ConfigurationManager.ConnectionStrings["AppDb"].ConnectionString,
                                             new ResolvedParameter<IRepositoryFactory>(),
                                             new ResolvedParameter<IPrincipalProvider>()))
                .RegisterType<IPersonService, PersonService>(new ContainerControlledLifetimeManager())
                .RegisterType<IPhotoService, PhotoService>(new ContainerControlledLifetimeManager());

            DependencyResolver.SetResolver(new UnityDependencyResolver(MvcUnity.Container));
            //IControllerFactory factory = new UnityControllerFactory(MvcUnity.Container);

            //ControllerBuilder.Current.SetControllerFactory(factory);
        }
    }
}